/**
 * Copyright (C), 2019-2020,个人开发
 * 文件名: ZxSsoConfig1
 * 作者: lsyzx【zhux@zhengebang.com】
 * 创建时间: 2019/2/24 15:16
 */
package com.zgb.manager.config;

import com.zx.sso.core.conf.Conf;
import com.zx.sso.core.filter.ZxSsoWebFilter;
import com.zx.sso.core.util.JedisUtil;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;

/**
 * 作者: lsyzx【zhux@zhengebang.com】
 * 创建时间: 2019/2/24 15:16
 * 描述: 单点登录客户端初始化
 * 历史修改:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
public class ZxSsoConfig implements DisposableBean {

    @Value("${sso.server}")
    private String xxlSsoServer;

    @Value("${sso.logout_path}")
    private String xxlSsoLogoutPath;

    @Value("${sso.excluded_paths}")
    private String xxlSsoExcludedPaths;

    @Value("${sso.redis_address}")
    private String xxlSsoRedisAddress;

    @Value("${sso.syscode}")
    private String sysCode;


    @Bean
    public FilterRegistrationBean xxlSsoFilterRegistration() {

        // xxl-sso, redis init
        JedisUtil.init(xxlSsoRedisAddress);

        // xxl-sso, filter init
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setName("zxSsoWebFilter");
        registration.setOrder(1);
        registration.addUrlPatterns("/*");
        registration.setFilter(new ZxSsoWebFilter());
        registration.addInitParameter(Conf.SSO_SERVER, xxlSsoServer);
        registration.addInitParameter(Conf.SSO_LOGOUT_PATH, xxlSsoLogoutPath);
        registration.addInitParameter(Conf.SSO_EXCLUDED_PATHS, xxlSsoExcludedPaths);
        registration.addInitParameter(Conf.SYSCODE, sysCode);
        return registration;
    }

    @Override
    public void destroy() throws Exception {

        // xxl-sso, redis close
        JedisUtil.close();
    }

}
